package test.keen.app.nav

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.application
import androidx.compose.ui.window.singleWindowApplication
import me.fung.keen.app.nav.Nav
import me.fung.keen.app.nav.PAGE_0
import me.fung.keen.app.nav.HOME
import me.fung.keen.app.nav.nav
import me.fung.keen.app.view.Presenter
import me.fung.keen.app.view.View
import me.fung.keen.component.message.MessageContent
import me.fung.keen.component.message.localMessage

class P1 : Presenter() {
    fun send() {

    }


}

class V1 : View<P1>() {
    @Composable
    override fun content(modifier: Modifier) {
        Button(onClick = {
            nav.goto(PAGE_0)
        }) {
            Text("Home")
        }
    }
}

class V2 : View<P1>() {
    @Composable
    override fun content(modifier: Modifier) {
        val msg = localMessage.current
        Column {
            Button(onClick = {
                nav.goBack()
            }) {
                Text("T1")
            }
            Button(
                onClick ={
                    msg.send{ info("send") }
                }
            ){
                Text("send")
            }
        }
    }
}

val nav: Nav = nav {
    HOME {
        V1()
    }
    PAGE_0 {
        V2()
    }
}

fun main() {
    singleWindowApplication {
        nav.goto(HOME)
        nav.show(Modifier)
        MessageContent().show(Modifier)
    }
}